﻿using UnityEngine;

namespace DL.Tools.SkyBoxRotate
{
    public class SkyBoxRotate : MonoBehaviour
    {
        [SerializeField]
        private float m_RotateSpeed = 0.002f;

        [SerializeField]
        private Camera m_MainCamera;

        private Skybox m_Skybox;

        private Material m_Material; 
        private void Start()
        {
            m_MainCamera ??= Camera.main;
            m_Skybox = m_MainCamera.GetComponent<Skybox>();
        }

        private void Update()
        {
            RotateSky();
        }

        public void RotateSky()
        {
            float rot = m_Skybox.material.GetFloat("_Rotation");
            m_Skybox.material.SetFloat("_Rotation", rot + m_RotateSpeed);
        }
    }
}